#include <stdio.h>

int main(int argc, char const *argv[])
{
    if(argc != 3)
    {
        printf("Pls input: ./a.out <dst file name> <src file name> \n");
        return -1;
    }

    FILE *fpDst = fopen(argv[1], "w");
    FILE *fpSrc = fopen(argv[2], "r");
    if(NULL == fpSrc || NULL == fpDst)
    {
        printf("Fail to open File\n");
        return -1;
    }

    char buff[1024] = {0};
    int ret;
    int iCounter = 0;
    while( (ret = fread(buff, sizeof(char), sizeof(buff), fpSrc) ) != 0 )
    {
        fwrite(buff, sizeof(char), ret, fpDst);
        iCounter += ret;
    }
    if( ferror(fpSrc) )
    {
        perror("Fail to fgets");
        return -1;
    }


    fclose(fpDst);
    fclose(fpSrc);

    printf("Success to copy total %d chars from src file <%s> to dst file <%s>\n",
            iCounter, argv[2], argv[1]);

    return 0;
}

/*
使用函数 fread 和 fwrite 实现 cp 功能
可以操作文本文件和二进制文件
*/